package br.com.abril.sforce;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import br.com.abril.sforce.SalesForceProfile.ProfileStatus;

@Controller
public class ProxyController {
	
	@Autowired
	private SalesForceProfileService profileService;
	
	@RequestMapping(value = "/rest/proxy/setup", method = RequestMethod.POST)
	public @ResponseBody ProxyEntry save (@RequestBody ProxyEntry proxyInfo) {
		profileService.getProxyProvider().setProxyEntry(proxyInfo);
		profileService.getProxyProvider().setProxyPreferences(proxyInfo);
		profileService.getProxyProvider().setUpProxy();
		profileService.getPreferences().saveLocalCache();
		profileService.notifyProxyIsChanged();
		
		return profileService.getProxyProvider().getProxyEntry();
	}	

	@RequestMapping(value = "/rest/proxy", method = RequestMethod.GET)
	public @ResponseBody ProxyEntry get () {
		return profileService.getProxyProvider().getProxyEntry();
	}	
	
}
